import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)
import menu from './modules/menu/index';
import role from './modules/role';
import user from './modules/user';
import cate  from './modules/cate';
import specs from './modules/specs';
import goods from './modules/goods';
import member from './modules/member';
import banner from './modules/banner';
import seck from './modules/seck';

export default new Vuex.Store({
  state: {
    userInfo: sessionStorage.getItem('userInfo') ? JSON.parse(sessionStorage.getItem('userInfo')) : null
    // userInfo:null
  },
  getters: {
    getUserInfo(state) {
      return state.userInfo
    }
  },
  mutations: {
    // 更改登录信息
    CHANGE_USERINFO(state, payload) {
      if (payload) {
        // 有登录信息
        state.userInfo = payload;
        // 将登录信息存储到会话存储
        sessionStorage.setItem('userInfo', JSON.stringify(payload));
      }else{
        sessionStorage.removeItem('userInfo')
      }

    }
  },
  actions: {
  },
  modules: {
    menu, role, user,cate,specs,goods,member,banner,seck
  }
})
